package com.example.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.model.domain.Student;
import com.example.mybatisplus.mapper.StudentMapper;
import com.example.mybatisplus.model.dto.PageDTO;
import com.example.mybatisplus.model.vo.StatisticVO;
import com.example.mybatisplus.service.StudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Override
    public List<StatisticVO> barChartData() {
        return baseMapper.barChartData();
    }

    @Override
    public List<StatisticVO> pieChartData() {
        return baseMapper.pieChartData();
    }

    @Override
    public List<StatisticVO> degreeStudentData() {
        return baseMapper.degreeStudentData();
    }

    @Override
    public List<StatisticVO> bksBedData() {
        return baseMapper.bksBedData();
    }

    @Override
    public List<StatisticVO> yjsBedData() {
        return baseMapper.yjsBedData();
    }

    @Override
    public List<StatisticVO> otherBedData() {
        return baseMapper.otherBedData();
    }

    @Override
    public Page<Student> pageList(Student student, PageDTO dto) {
        QueryWrapper<Student> wrapper = new QueryWrapper<>();
        if (Objects.nonNull(student.getYqStudent())){
            wrapper.like("yq_student",student.getYqStudent());
        }
        if (Objects.nonNull(student.getBuildingsStudent())){
            wrapper.eq("buildings_student",student.getBuildingsStudent());
        }
        if (Objects.nonNull(student.getRoomsStudent())){
            wrapper.likeRight("rooms_student",student.getRoomsStudent());
        }
        wrapper.eq("hasbed_student",true).eq("degree_student","本科生");
        Page<Student> page = new Page<>();
        page.setCurrent(dto.getPageNo()).setSize(dto.getPagesize());
        baseMapper.selectPage(page,wrapper);
        return page;
    }

    @Override
    public Page<Student> yanPageList(Student student, PageDTO dto) {
        QueryWrapper<Student> wrapper = new QueryWrapper<>();
        if (Objects.nonNull(student.getYqStudent())){
            wrapper.like("yq_student",student.getYqStudent());
        }
        if (Objects.nonNull(student.getBuildingsStudent())){
            wrapper.eq("buildings_student",student.getBuildingsStudent());
        }
        if (Objects.nonNull(student.getRoomsStudent())){
            wrapper.likeRight("rooms_student",student.getRoomsStudent());
        }
        wrapper.eq("hasbed_student",true)
                .like("degree_student","研究生");
        Page<Student> page = new Page<>();
        page.setCurrent(dto.getPageNo()).setSize(dto.getPagesize());
        baseMapper.selectPage(page,wrapper);
        return page;
    }

}
